package ssm.controller;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ssm.dao.WorkArrange;
import ssm.model.WorkArrangeMapper;
import ssm.utils.TimeUtils;

import java.sql.Time;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Controller
public class Init_WorkArrange {

@Autowired
private WorkArrangeMapper workArrangeMapper;

@RequestMapping("/init_work")
@ResponseBody
    public void init(){
        LocalDateTime dateTime=LocalDateTime.now();
        String year=dateTime.getYear()+"";
        String start=year+"-01-01";
        String end=year+"-12-31";
        try {
            List<String> dates = TimeUtils.findDates(start, end);
            WorkArrange workArrange=new WorkArrange();
            for(String date:dates){
                workArrange.setDate(date);
                workArrange.setYear(year);
                workArrange.setUpdatime(null);
                if(TimeUtils.isZhoumo(date)){
                    workArrange.setDescr("周末");
                    workArrange.setStatus(4);

                }else{
                    workArrange.setDescr("上班");
                    workArrange.setStatus(1);
                }
                workArrangeMapper.insert(workArrange);
            }


        } catch (ParseException e) {
            System.out.println("日期格式错误,请联系码农解决");
        }
    }
}
